// index.js
// 获取应用实例
const app = getApp()
Page({
  data: {
    isGo: false
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad (options) {
    let type = options.type
    let arr = app.globalData.appAddressList.filter((item) => item.type == type)
    if (arr[0]) {
      this.setData({ isGo: true })
      this.leadTo(arr[0].weburl, arr[0].registerurl)
    }
  },

  onShow () {
    if (this.data.isGo) {
      wx.reLaunch({
        url: '/pages/index/index'
      })
    }
  },

  leadTo(url, regurl) {
    const weburl = url
    const registerurl = regurl || ""
    let wx_weburl = weburl;
    if (!wx_weburl.startsWith('http')) {
      wx_weburl = "https://enterprise.e-cology.com.cn/login/LoginForSSO.jsp?loginid=ywy&userpassword=1&gopage=https://enterprise.e-cology.com.cn" + encodeURIComponent(wx_weburl) ;

    }
    if (registerurl) {
        let wx_registerurl = registerurl
        if (registerurl.startsWith('/')) {
            wx_registerurl = location.protocol + "//" + location.host + registerurl;
        }
        wx.navigateTo({ url: `../webview/webview?weburl=${encodeURIComponent(wx_weburl)}&registerurl=${encodeURIComponent(wx_registerurl)}` });
    } else {
        wx.navigateTo({ url: `../webview/webview?weburl=${encodeURIComponent(wx_weburl)}` });
    }
  },
})